package proxy_jdk;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName HuGeProxy2
 * @Date 2021/7/27 10:18
 * @Author 李明杰
 * @Description
 */

public class HuGeProxy2 {
    Star star;

    public void setStar(Star star) {
        this.star = star;
    }

    public Star getProxy() {
        return (Star) Proxy.newProxyInstance(getClass().getClassLoader(), star.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("我是胡歌代理2号，有事找我");
                return method.invoke(star, args);
            }
        });
    }
}
